<?php
/*
 * dashboard element to display user's projects
*/
include("../inc_files/utils/checksession.php");
// Create connection
include("../inc_files/utils/dbconnection.php");
$userID = $_SESSION["userid"];
//query for all projects not deleted
$query ="SELECT projects.ProjectID, projects.ProjectTitle
FROM projects WHERE projects.Deleted != 1 AND ProjectManager='".$userID."' ORDER BY projects.ProjectID";
$result = $mysqli->query( $query );

//count the number of returned results
$resultCount = $result->num_rows;

//if there are some results returned create a table showing the results
if( $resultCount > 0){
	$rownumber = 0;

	echo "<table class='datagrid'>
			<tr class=\"datagrid headerrow\">
			<th  style=\"width:30%\">ProjectID</a></th>
			<th style=\"width:65%\">Project Title</a></th>
			<th style=\"width:5%\">Edit</th>
			</tr>";

	while($row = mysqli_fetch_array($result))
	{

		if($rownumber %2 == 0)
		{
			echo "<tr class=\"datagrid evenrow\">";
		}
		else
		{
			echo "<tr class=\"datagrid oddrow\">";
		}
		echo "<td style=\"width:30%\">" . $row['ProjectID'] . "</td>";
		echo "<td style=\"width:65%\">" . $row['ProjectTitle'] . "</td>";
		echo "<td style=\"width:5%\"><input type=\"image\"  height=\"24\" width=\"24\"  src=\"../images/pencil_24.png\" alt=\"Edit project ". $row['ProjectID'] ."\" onclick=\"window.location.href='../projects/editproject.php?projectid="  . $row['ProjectID'] . "'\"></td>";
		echo "</tr>";
		$rownumber++;
	}
	echo "</table>";
}
//if no results returned say so.
else
{

	echo"No records returned";
}
//tidy up database connection
$mysqli->close();


?>